<template>
	<el-dialog :title="!dataForm.id ? '新建' :  isDetail ? '详情':'编辑'" :close-on-click-modal="false" :visible.sync="visible" class="JNPF-dialog JNPF-dialog_center" lock-scroll width="600px">
		<el-row :gutter="15" class="" >
			<el-form ref="elForm" :model="dataForm" size="medium" label-width="180px" label-position="right" :disabled="!!isDetail" :rules="rules">
				<el-col :span="24">
					<el-form-item label="最小风险值" prop="minvalue" required >
						<el-input v-model="dataForm.minvalue" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="最大风险值" prop="maxvalue" required >
						<el-input v-model="dataForm.maxvalue" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="风险描述" prop="des" required >
						<el-input v-model="dataForm.des" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="应采取的行动/控制措施" prop="kzcs" required >
						<el-input v-model="dataForm.kzcs" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="实施期限" prop="ssqx" required >
						<el-input v-model="dataForm.ssqx" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<!-- <el-col :span="24">
					<el-form-item label="评价方法类型(LEC或LS)" prop="type" required >
						<el-select v-model="dataForm.type" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in typeOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col> -->
				<el-col :span="24">
					<el-form-item label="风险等级" prop="level" required >
						<el-select v-model="dataForm.level" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in levelOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
			</el-form>
		</el-row>
		<span slot="footer" class="dialog-footer">
			<el-button @click="visible = false">取 消</el-button> 
			<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
		</span>
	</el-dialog>

</template>
<script>
import request from '@/utils/request'
import {getDictionaryDataSelector}from '@/api/systemData/dictionary'
import {previewDataInterface}from '@/api/systemData/dataInterface'
export default {
    data() {
      return {
        visible: false,
        isDetail: false,
        dataForm: {
					minvalue:undefined,
					maxvalue:undefined,
					des:undefined,
					kzcs:undefined,
					ssqx:undefined,
					type:'LS',
					level:undefined,

        },
        rules: {
						minvalue:[
						{
							required:true,
							message:'请输入最小风险值',
							trigger:'blur'
						},
						],
						maxvalue:[
						{
							required:true,
							message:'请输入最大风险值',
							trigger:'blur'
						},
						],
						des:[
						{
							required:true,
							message:'请输入风险描述',
							trigger:'blur'
						},
						],
						kzcs:[
						{
							required:true,
							message:'请输入应采取的行动/控制措施',
							trigger:'blur'
						},
						],
						ssqx:[
						{
							required:true,
							message:'请输入实施期限',
							trigger:'blur'
						},
						],
						type:[
						{
							required:true,
							message:'请输入评价方法类型(LEC或LS)',
							trigger:'blur'
						},
						],
						level:[
						{
							required:true,
							message:'请输入风险等级',
							trigger:'blur'
						},
						],

        },
				typeOptions:[{"fullName":"LEC","id":"LEC"},{"fullName":"LS","id":"LS"}],
				levelOptions:[{"fullName":"重大风险","id":"重大风险"},{"fullName":"较大风险","id":"较大风险"},{"fullName":"一般风险","id":"一般风险"},{"fullName":"低风险","id":"低风险"}],


      }
    },
    created() {

    },
    methods: {

           goBack() {
                    this.$emit('refresh')
                },
      init(id, isDetail) {

        this.dataForm.id = id || 0;
        this.visible = true;
        this.isDetail = isDetail || false;
        this.$nextTick(() => {
          this.$refs['elForm'].resetFields();
          if (this.dataForm.id) {
            request({
              url: '/api/System/rsikMeasures/' + this.dataForm.id,
              method: 'get'
            }).then(res =>{
              this.dataForm = res.data;

            })
          }
        })
      },
      // 表单提交
      dataFormSubmit() {

        this.$refs['elForm'].validate((valid) => {
          if (valid) {
            if (!this.dataForm.id) {
              request({
                url: '/api/System/rsikMeasures',
                method: 'post',
                data: this.dataForm,
              }).then((res) =>{
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () =>{
                    this.visible = false;
                    this.$emit('refresh', true);
                  }
                })
              })
            } else {
              request({
                url: '/api/System/rsikMeasures/' + this.dataForm.id,
                method: 'PUT',
                data: this.dataForm
              }).then((res) =>{
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () =>{
                    this.visible = false;
                    this.$emit('refresh', true);
                  }
                })
              })
            }
          }
        })
      },

    }
  }
  </script>